home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Workbench Add-On
/
Workbench Add-On - Volume 1.iso
/
BBS-Archive
/
Comm
/
AmiTCP30b2.lha
/
src
/
netlib
/
utime.c
< prev
Wrap
C/C++ Source or Header
|
1994-03-29
|
3KB
|
127 lines
RCS_ID_C="$Id: utime.c,v 3.1 1994/03/29 12:56:35 ppessi Exp $"
/*
* utime.c --- set the modification date of the file
*
* Author: jraja <Jarno.Rajahalme@hut.fi>
*
* Copyright © 1994 AmiTCP/IP Group, <amitcp-group@hut.fi>
* Helsinki University of Technology, Finland.
* All rights reserved.
*
* Created : Thu Mar 24 22:30:12 1994 jraja
* Last modified: Mon Mar 28 01:53:14 1994 ppessi
*
* $Log: utime.c,v $
* Revision 3.1 1994/03/29 12:56:35 ppessi
* Made to use netlib.h
*
* Revision 1.1 1994/03/27 11:53:06 jraja
* Initial revision
*
*
*/
#include <sys/param.h>
#include <sys/time.h>
#include <dos/dos.h>
#include <proto/dos.h>
#include <utime.h>
#include <errno.h>
#include <syslog.h>
#include "netlib.h"
/****** net.lib/utime *********************************************
NAME
utime - set file access and modification times
SYNOPSIS
#include <utime.h>
int error = utime(const char *name, const struct utimbuf *times)
FUNCTION
The access and modification times for the file 'name' are modified
according to the 'times'. If 'times' is NULL, the times are set to
systems current time.
PORTABILITY
UNIX
INPUTS
'name' - the name of the file to be affected.
'times' - pointer to a structure containing the time values,
defined in <utime.h> as:
struct utimbuf {
time_t actime; \* Access time *\
time_t modtime; \* Modification time *\
};
Both times are in units of seconds since Jan. 1, 1970,
Greenwich Mean Time.
If the 'times' is given as the NULL pointer, the current
time is used.
RESULT
Returns 0 when successful and -1 with specific error code in errno in
case of an error.
NOTES
Since AmigaDOS files have only one time stamp, both access and
modification times cannot be supported. Since the AmigaDOS file date
is the modification time, only the 'modtime' field of the 'times' is
used.
The conversion from 1.1.1970 based GMT to 1.1.1978 based local time is
done with external long __local_to_GMT, which is defined and
initialized by the timerinit.c module included in the net.lib.
SEE ALSO
dos.library/DateStamp(), dos.library/SetFileDate(), net.lib/timerinit
*****************************************************************************
*
*/
extern long __local_to_GMT; /* defined and initialized in timerinit.c */
int
utime(const char *name, const struct utimbuf *times)
{
struct DateStamp stamp;
unsigned long days, secs;
time_t time;
if (times == NULL)
DateStamp(&stamp);
else {
/*
* AmigaDOS file date is the modification time
*/
time = times->modtime;
/*
* Convert time (secs since 1.1.1970 GMT) to
* AmigaDOS DateStamp (based on 1.1.1978 local time).
*/
time -= __local_to_GMT; /* GMT to local */
days = (unsigned long)time / (unsigned long)(24*60*60);
secs = (unsigned long)time % (unsigned long)(24*60*60);
stamp.ds_Days = (LONG)days;
stamp.ds_Minute = (LONG)(secs / 60);
stamp.ds_Tick = (LONG)((secs % 60) * TICKS_PER_SECOND);
}
if (!SetFileDate(name, &stamp)) {
set_errno(IoErr());
return -1;
}
return 0;
}